/*
 The surface-physics project: http://code.google.com/p/surface-physics/
 Adds real world physics based on the Bullet physics engine, to bases in the Orbiter space
 flight simulation software.

 Written by Abhijit Nandy
 License : Apache License 2.0

 VesselCollisionDef.h

 Used to hold the description of a vessel's collision mesh in memory for
 use as vessels require a collider.

 The compound shape has all the simpler shapes used to make the chassis in ANY mode.

*/

#include "LinearMath/btVector3.h"
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
#include "orbitersdk.h"


enum CollisionMeshType {
	CMT_VEHICLE,
	CMT_MESH
};

struct VesselCollisionDef {

	// Constants
	static const int MAX_VESSEL_SIZE = 1000;
	static const int MAX_WHEELS = 4;
	static const int MAX_SHAPES = 16;

	// TODO: Support for editing the definition and detect when to save it
	bool isDirty;


	// Vehicle or mesh collider
	CollisionMeshType collMeshType;

	//-------------------------Wheel----------------------


	//Wheel parameters
	float	frontWheelRadius, backWheelRadius;
	float	frontWheelHalfWidth, backWheelHalfWidth;	 //actual width is twice!
	float	frontWheelFriction, backWheelFriction;
	int 	rightIndex;
	int 	upIndex;
	int 	forwardIndex;
	float	frontConnectionHeight, backConnectionHeight; //y is the connection ht., not Y position
	btVector3	wheelDirection;
	btVector3 	wheelAxle;
	btCollisionShape	*frontWheelShape, *backWheelShape; //only 2 kinds of wheels

	// Orbiter wheel animation by physics
	bool 	isWheelInfoSet[MAX_WHEELS];
	UINT 	wheelMeshIndex;
	int 	wheelMeshGroupIndex[MAX_WHEELS];
	int 	wheelStrutMeshGroupIndex[MAX_WHEELS];
	VECTOR3 wheelMeshGroupCenter[MAX_WHEELS]; 	// supplied by user as GetMesh() cannot be used yet
	int 	numWheels;  //upto MAX_WHEELS

	//-----------------------Chassis --------------------------

	//Suspension parameters
	float	frontSuspensionStiffness, backSuspensionStiffness;
	float	frontSuspensionDamping, backSuspensionDamping;
	float	frontSuspensionCompression, backSuspensionCompression;
	float 	frontSuspensionRestLength, backSuspensionRestLength;
	float	rollInfluence;

	//Heights and initial location
	float 	initialVehicleHeight; //Height from which vehicle should be dropped on terrain at physics start
	float 	chassisLocalHeight; //Height of chassis above vehicle origin

	// Shared by all vessels, the chassis shape may mix shapes defined by multiple MSH & basic shapes
	btCollisionShape	*chassisShapes[MAX_SHAPES]; 		//array of shapes - each shape data must persist
	btTransform			chassisShapeTransforms[MAX_SHAPES]; 	//array of offsets
	int 	numShapes;
	char    *chassisShapeFileNames[MAX_SHAPES];


	//----------------------------------------------------------------

	// Keep track of how many base objects are sharing this collision definition
	int 	numSharing;


};


#pragma once
